package com.liangtian.mdm.base.response;

import com.liangtian.mdm.base.constants.ResultCode;
import lombok.Data;

/**
 * 基础响应类
 *
 * @author Qi
 */
@Data
public class BaseResponse {
    private String code;
    private String message;
    private Object data;


    public static BaseResponse genResponse(String code, String message, Object data) {
        return new BaseResponse(code,message,data);
    }

    public static BaseResponse genResponse(ResultCode code, Object data) {
        return new BaseResponse(code.getCode(), code.getMsg(), data);
    }

    public static BaseResponse genResponse(String code, String message) {
        return new BaseResponse(code,message,null);
    }

    public static BaseResponse genResponse(ResultCode code) {
        return new BaseResponse(code.getCode(), code.getMsg(), null);
    }

    public BaseResponse ok() {
        this.code = ResultCode.SUCCESS.getCode();
        this.message = ResultCode.SUCCESS.getMsg();
        return new BaseResponse(code, message, null);
    }

    /**
     * 自定义成功返回语句
     * @param message 成功提示
     * @return
     */
    public BaseResponse ok(String message) {
        this.code = ResultCode.SUCCESS.getCode();
        this.message = message;
        this.data = null;
        return new BaseResponse(code, message, data);
    }

    public BaseResponse ok(String message,Object data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.message = message;
        this.data = null;
        return new BaseResponse(code, message, data);
    }


    public BaseResponse ok(Object data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.message = ResultCode.SUCCESS.getMsg();
        this.data = data;
        return new BaseResponse(code, message, data);
    }

    public BaseResponse fail(String code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
        return new BaseResponse(code, message, null);
    }



    public BaseResponse() {
    }

    public BaseResponse(String code, Object data) {
        this(code, null, data);
    }


    public BaseResponse(String code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
